constructors, destructors
constructor function:
1. If no constructor is provided, the system automatically provides a default constructor that initializes all members as default values (reference type is null reference NULL, value type is 0,bool
Item 8:prevent exceptions from leaving destructors.
Destructors do not throw exceptions
Because destructors are often invoked on their own initiative, exceptions thrown in destructors are often difficult to capture, triggering an abnormal
Use of destructors: (1). You cannot define destructors in structs, you can only use destructors on classes. (2). A class can have only one destructor. (3). Destructors cannot be inherited and overloaded (4). Destructors cannot be called manually, it
1. Don't let the exception escape the reason for the destructor
Article 08 of the third edition of effective C + + recommends that you do not throw an exception in a destructor because the C + + exception mechanism cannot handle two or more than
1. Why should destructors not throw exceptions?There are two types of situations:1). If there are many statements in the destructor, and the first statement throws an exception (or other statement), then the statement after the exception is thrown
Ilocker: Focus on Android Security (novice) qq:25972942871 classTransaction {//base class for all transactions2 Public:3 Transaction ();4 Virtual voidLogtransaction ()Const=0;//make a different type of log record5 ... ..6 }7
+-------------------------------------------------------------------------------+
| = This is haohappy read
>
| = Notes in Classes and objects Chapter
| = Translation-based + personal experience
| = Please do not reprint in order to avoid the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.